package com.ysy.logistics.controller.sale;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ysy.common.resp.ResultData;
import com.ysy.logistics.entities.sale.CusOrder;
import com.ysy.logistics.entities.sale.dto.CusOrderDto;
import com.ysy.logistics.myannotation.OperateLog;
import com.ysy.logistics.service.sale.CusOrderService;
import com.ysy.logistics.util.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassDescription:
 * @Author:姚斯羽
 * @Create:2025/4/9 22:52
 **/
@Slf4j
@RestController
@RequestMapping(value = "/cusOrder",name = "销售单")
@Tag(name = "销售订单管理",description = "cusOrder表的CRUD")
@CrossOrigin
public class CusOrderController {

    @Resource
    private CusOrderService cusOrderService;

    @PostMapping("/listByPage")
    @Operation(summary = "分页查询",description = "分页查询")
    @OperateLog(value = "销售单查询")
    public ResultData<Page<CusOrder>> listByPage(@RequestBody PageInfo<CusOrder> pageInfo){
        return ResultData.success( cusOrderService.listByPage(pageInfo));
    }

    @PostMapping("/save")
    @Operation(summary = "新增",description = "新增")
    @OperateLog(value = "销售单新增")
    public ResultData<String> save(@RequestBody CusOrderDto cusOrderDto){
        log.info("新增订单：{}",cusOrderDto);
        return cusOrderService.saveSupOrderDto(cusOrderDto);

    }

    @GetMapping("/getGoodsListByOrderId/{id}")
    @Operation(summary = "根据订单id查询商品",description = "根据订单id查询商品")
    public ResultData getGoodsListByOrderId(@PathVariable("id") String id){
        return ResultData.success(cusOrderService.getGoodsListByOrderId(id));
    }

    @GetMapping("/outBout/{id}")
    @Operation(summary = "出库",description = "出库")
    @OperateLog(value = "销售单出库")
    public ResultData outBout(@PathVariable("id") String id){
        return cusOrderService.outBoutById(id);
    }

    @GetMapping("/flushOrder")
    @Operation(summary = "刷新订单",description = "刷新订单")
    @OperateLog(value = "销售单刷新")
    public ResultData flushOrder(){
        cusOrderService.flushOrder();
        return ResultData.success();
    }

    @GetMapping("/backOrder/{id}")
    @Operation(summary = "退货",description = "退货")
    @OperateLog(value = "销售单退货")
    public ResultData backOrder(@PathVariable("id") String id){
        return cusOrderService.backOrder(id);
    }
}
